package com.dfbz.netctoss.mapper;

import com.dfbz.netctoss.entity.Role;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface RoleMapper extends Mapper<Role> {

    @Select("select * from role")
    @Results(
            {
                    @Result(property = "roleId", column = "role_id", id=true),
                    @Result(property = "privileges",column = "role_id",many = @Many(select = "com.dfbz.netctoss.mapper.PrivilegeMapper.selectByRId"))
            }

    )
    List<Role> findRoles();
//
//    @Select("select * from role where role_id = #{roleId}")
//    @Results(
//            {
//                    @Result(property = "roleId", column = "role_id", id=true),
//                    @Result(property = "privileges",column = "role_id",many = @Many(select = "com.dfbz.netctoss.mapper.PrivilegeMapper.selectAllPrivilegeByRId"))
//            }
//
//    )
//    Role findAllPrivilegeByRoleId(@Param("roleId") Integer roleId);

    @Select("select role.* " +
            "from role,admin_role ar,admin_info ai " +
            "where role.role_id = ar.role_id " +
            "and ar.admin_id = ai.admin_id " +
            "and ai.admin_id = #{adminId}")
    List<Role> findRolesByAdminId(@Param("adminId") Integer adminId);
}